#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QButtonGroup>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //pushButton
    ui->pushButton->setIcon(QIcon(":/image/ii.webp"));
    ui->pushButton->setIconSize(QSize(100,112));

    ui->pushButton_left->setIcon(QIcon(":/image/left.png"));
    ui->pushButton_left->setIconSize(QSize(50,50));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_left->setAutoRepeat(true);

    ui->pushButton_right->setIcon(QIcon(":/image/right.png"));
    ui->pushButton_right->setIconSize(QSize(50,50));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));
    ui->pushButton_right->setAutoRepeat(true);

    ui->pushButton_up->setIcon(QIcon(":/image/up.png"));
    ui->pushButton_up->setIconSize(QSize(50,50));
    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_up->setAutoRepeat(true);

    ui->pushButton_down->setIcon(QIcon(":/image/down.png"));
    ui->pushButton_down->setIconSize(QSize(50,50));
    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_down->setAutoRepeat(true);


    //radioButton
    //ui->radioButton->setAutoExclusive(false);

    //按钮分组
    QButtonGroup* group1=new QButtonGroup(this);
    QButtonGroup* group2=new QButtonGroup(this);

    group1->addButton(ui->radioButton_4);
    group1->addButton(ui->radioButton_5);
    group1->addButton(ui->radioButton_6);

    group2->addButton(ui->radioButton_7);
    group2->addButton(ui->radioButton_8);
    group2->addButton(ui->radioButton_9);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_left_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()-10,rect.y(),rect.width(),rect.height());
}
void Widget::on_pushButton_right_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()+10,rect.y(),rect.width(),rect.height());
}
void Widget::on_pushButton_up_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()-10,rect.width(),rect.height());
}
void Widget::on_pushButton_down_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()+10,rect.width(),rect.height());
}

void Widget::on_radioButton_clicked()
{
    ui->label->setText("你喜欢的水果是：苹果");
}

void Widget::on_radioButton_2_clicked()
{
    ui->label->setText("你喜欢的水果是：香蕉");
}

void Widget::on_radioButton_3_clicked()
{
    ui->label->setText("你喜欢的水果是：橘子");
}



void Widget::on_pushButton_2_clicked()
{
    QString s="今天中午你吃 ";
    if(ui->checkBox_l->isChecked())
    {
        s+="螺蛳粉";
        s+="和";
    }
    if(ui->checkBox_s->isChecked())
    {
        s+="酸辣粉";
        s+="和";
    }
    if(ui->checkBox_y->isChecked())
    {
        s+="油泼面";
    }

    ui->label_food->setText(s);
}
